package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.VideoInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;
import com.xgkj.diyiketang.util.LogUtils;

/**
 * Created by Administrater on 2015/12/7.
 */
public class VideoDetailTask extends CouponHttpBaseTask {
    private String mVideoId;
    private static final String VIDEODETAILJSON = "data";

    public VideoDetailTask(String videoId) {
        super(TaskType.VIDEO_DETAIL_TASK);
        mVideoId = videoId;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject respJson = response.getBody();

//        VideoInfo info = null;
//        if (respJson != null) {
//            info = JSON.parseObject(respJson.getString(VIDEODETAILJSON), VideoInfo.class);
//        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, respJson);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest(RequestType.VIDEO_DETAIL_REQUEST);
            JSONObject json = new JSONObject();
            json.put("videoId", mVideoId);
            request.setData(json.toString());
            request.setApiNo(ApiNo.VIDEO_DETAIL);
            addRequest(request);
        }
    }
}
